<template>
	<view class="process">
		<view class="content_box">
			<view class="jindu_box flex">
				<view :class="[listIndex == index ? 'jindu_list_active' : 'jindu_list']" v-for="(item, index) in 5" :key="index"></view>
			</view>
			<block v-if="listIndex == 0">
				<view class="con_title s48 familytow fblod">选择购买分类</view>
				<view class="list_box flex">
					<view
						:class="[fenListIndex == index ? 'fen_list_active' : '', 'fen_list', 'txtali', 's28', 'f500', 'family']"
						v-for="(item, index) in fenLeiCList"
						:key="index"
						@click="active(index, item.id)"
					>
						{{ item.name }}
					</view>
				</view>
			</block>
			<view v-show="listIndex == 1">
				<view class="con_title s48 familytow fblod">选择商家</view>
				<view class="select">
					<select-list ref="select" :list="shopList"></select-list>
				</view>
			</view>
			<block v-if="listIndex == 2">
				<view class="con_title s48 familytow fblod">输入推荐客户信息</view>
				<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y">
					<view class="ipt_box" v-for="(item, type) in userList" :key="type">
						<view class="ipt_list_box flex">
							<view class="name s30 f500 family">姓名</view>
							<input class="uni-input" v-model="item.name" placeholder="请输入姓名" />
						</view>
						<view class="ipt_list_box flex">
							<view class="name s30 f500 family">电话</view>
							<input class="uni-input" v-model="item.mobile" placeholder="请输入电话" maxlength="11" />
						</view>
						<view class="ipt_list_box flex">
							<view class="name s30 f500 family">性别</view>
							<picker @change="bindPickerChange($event, type)" mode="selector" :value="item.sex" :range="item.array" range-key="name">
								<view class="uni-input" style="">{{ item.array[item.sex].name }}</view>
							</picker>
						</view>
					</view>
				</scroll-view>
				<view class="text_area f500 family s20">强调：推荐结婚消费客户，强烈建议您增加双方资料信息以免他人用另外一方的电话下单后，您失去推荐资格。</view>
				<view class="btn_tuijian" v-if="userList.length != 2">
					<view class="con_box flex">
						<view class="jia_img">
							<image class="w100 h100" src="../static/jia.png" mode=""></image>
						</view>
						<view class="add_tuijian f500 family s28" @click="clickParent">增加推荐客户信息</view>
					</view>
				</view>
			</block>
			<block v-if="listIndex == 3">
				<view class="con_title s48 familytow fblod">意向产品选择</view>
				<view class="list_box flex">
					<view
						:class="[item.flag ? 'fen_list_active' : '', 'fen_list', 'txtali', 's28', 'f500', 'family']"
						v-for="(item, index) in shopClassList"
						:key="index"
						@click="activeTwo(index)"
					>
						{{ item.name }}
					</view>
				</view>
			</block>
			<block v-if="listIndex == 4">
				<view class="con_title s48 familytow fblod">确认信息</view>
				<view class="xuan_ze_box">
					<view class="xuan_txt s28 f500 family">选择购买分类</view>
					<view class="xuanze_list f500 s28 family">
						{{ fenTwoCTxt }}
					</view>
				</view>
				<view class="xuan_ze_box">
					<view class="xuan_txt s28 f500 family">选择商家</view>
					<view class="xuanze_list f500 s28 family">
						{{ iptVal }}
					</view>
				</view>
				<view class="xuan_ze_box">
					<view class="xuan_txt s28 f500 family">输入推荐客户信息</view>
					<view class="xuanze_list f500 s28 family" style="height: 164upx" v-for="(item, index) in userList" :key="index">
						<view class="flex_box flex">
							<view class="name_list s28 f500 family">姓名</view>
							<view class="name_list_c s28 f500 family">
								{{ item.name }}
							</view>
						</view>
						<view class="flex_box flex">
							<view class="name_list s28 f500 family">电话</view>
							<view class="name_list_c s28 f500 family">
								{{ item.mobile }}
							</view>
						</view>
						<view class="flex_box flex">
							<view class="name_list s28 f500 family">性别</view>
							<view class="name_list_c s28 f500 family">
								{{ item.index == 1 ? '男' : '女' }}
							</view>
						</view>
					</view>
				</view>
				<view class="xuan_ze_box">
					<view class="xuan_txt s28 f500 family">意向产品选择</view>
					<view class="xuanze_list f500 s28 family flex flex-wrap">
						<block v-for="(item, index) in fenTwoTxt" :key="index">
							<view style="margin-right: 20rpx">{{ item }}</view>
						</block>
					</view>
				</view>
			</block>
			<view class="btn-flii"></view>
			<view class="btn s32 familytow fblod txtali" @click="Next">
				{{ updata }}
			</view>
		</view>
		<view class="beijing" v-if="show">
			<view class="beij_con_box">
				<view class="beij_txt s30 family f500">
					{{ bbTxt }}
				</view>
				<view class="my_yes s32 familytow fblod txtali" @click="noBeij">我知道了</view>
			</view>
		</view>
	</view>
</template>

<script>
import selectList from '@/components/selectList.vue';
export default {
	components: {
		selectList
	},
	data() {
		return {
			listIndex: 2,
			fenListIndex: null,
			fenTwoListIndex: null,
			fenTwoTxt: [],
			fenTwoCTxt: '',
			myName: '',
			myPhone: '',
			op: '西红柿',
			number: 1,
			iptVal: '',
			updata: '下一步',
			show: false,
			userList: [
				{
					name: '',
					sex: 0,
					array: [
						{
							name: '请选择性别'
						},
						{
							name: '男'
						},
						{
							name: '女'
						}
					],
					mobile: ''
				}
			],
			userInfo: {
				name: '',
				sex: 0,
				array: [
					{
						name: '请选择性别'
					},
					{
						name: '男'
					},
					{
						name: '女'
					}
				],
				mobile: ''
			},
			shopList: [],
			fenLeiCList: [],
			shopClassList: [],
			shopId: 0,
			catId: -1,
			goodsId: [],
			bbTxt: '',
			typeUp: true
		};
	},
	onLoad(options) {
		let obj = JSON.parse(decodeURIComponent(options.obj));

		this.iptVal = obj.iptVal;
		this.shopId = obj.shopId;
		this.catId = obj.catId;
		this.fenListIndex = obj.fenListIndex;
		this.fenTwoCTxt = obj.fenTwoCTxt;
	},
	onShow() {
		this.listIndex = 2;
	},
	methods: {
		clickParent() {
			this.userList.push(this.userInfo);
		},
		getNavsList() {
			let that = this;
			that
				.$request({
					url: 'common/categoryList'
				})
				.then((res) => {
					if (res.statusCode == 200) {
						res.data.data.unshift({
							name: '摄影服务',
							id: 0
						});
						that.fenLeiCList = res.data.data;
					}
				});
		},
		getStoreList() {
			let that = this;
			that
				.$request({
					url: 'shop/getReferrerShop',
					data: {
						catid: that.catId,
						top: that.catId == 0 ? 1 : 0
					}
				})
				.then((res) => {
					if (res.data.code == 1) {
						that.shopList = res.data.data;
					}
				});
		},
		noBeij() {
			this.show = false;
		},
		bindPickerChange: function (e, ind) {
			let that = this;
			that.userList[ind].sex = e.target.value;
		},
		active(index, id) {
			this.fenListIndex = index;
			this.fenTwoCTxt = this.fenLeiCList[index].name;
			this.catId = id;
		},
		activeTwo(index) {
			this.shopClassList[index].flag = !this.shopClassList[index].flag;
		},
		Next() {
			let that = this,
				list = [],
				step = 0;
			if (that.listIndex == 0) {
				if (that.catId == -1) {
					that.$wanlshop.msg('请选择分类');
					that.listIndex--;
				} else {
					that.getStoreList();
				}
			}
			if (that.listIndex == 1) {
				if (that.iptVal == '') {
					that.$wanlshop.msg('请选择店铺名称');
					that.listIndex--;
				}
			}
			if (that.listIndex == 2) {
				if (that.userList[0].name == '' && that.userList[0].mobile == '' && that.userList[0].sex == 0) {
					that.$wanlshop.msg('填写信息是否完整');
					return;
					that.listIndex--;
				}
				that
					.$request({
						url: 'shop/getnewproduct',
						method: 'POST',
						data: {
							cat_id: that.catId
						}
					})
					.then((res) => {
						res.data.data.forEach((item) => {
							item.flag = false;
						});
						that.shopClassList = res.data.data;
					});
			}
			if (that.listIndex == 3) {
				that.shopClassList.forEach((item) => {
					if (item.flag) {
						that.fenTwoTxt.push(item.name);
						that.goodsId.push(item.id);
					}
				});
			}
			if (that.listIndex == 4) {
				that.updata = '提交';
			}
			if (that.listIndex == 2) {
				let obj = {
					iptVal: that.iptVal,
					shopId: that.shopId,
					catId: that.catId,
					fenListIndex: this.fenListIndex,
					fenTwoCTxt: this.fenTwoCTxt,
					userList: that.userList
				};
				uni.navigateTo({
					url: `/pages/filePages/membershipPage/process4?obj=${encodeURIComponent(JSON.stringify(obj))}`
				});
			}
			return;

			if (that.listIndex > 4) {
				that.userList.forEach((item, index) => {
					list.push({
						username: item.name,
						sex: item.sex,
						mobile: item.mobile
					});
				});
				if (that.typeUp) {
					step = 0;
				} else {
					step = 1;
				}
				this.$request({
					url: 'customer/recommend',
					method: 'POST',
					data: {
						cat_id: that.catId,
						step: step,
						shop_id: that.shopId,
						product_id: that.goodsId,
						users: list
					}
				}).then((res) => {
					if (res.data.code == 1) {
						uni.navigateTo({
							url: './upData'
						});
					} else if (res.data.code == -1) {
						that.typeUp = false;
						that.bbTxt = res.data.msg;
						that.show = true;
						that.listIndex--;
					} else if (res.data.code == 0) {
						uni.showModal({
							title: '提示',
							content: res.data.msg,
							showCancel: false,
							success: function (res) {
								if (res.confirm) {
									uni.switchTab({
										url: '/pages/member/member'
									});
								}
							}
						});
						that.listIndex--;
					}
				});
			}
		}
	}
};
</script>

<style scoped lang="scss">
.process {
	overflow: hidden;

	.beijing {
		width: 750upx;
		height: 1614upx;
		position: fixed;
		top: 0;
		background: rgba(0, 0, 0, 0.5);

		.beij_con_box {
			width: 552upx;
			height: 348upx;
			background: #ffffff;
			border-radius: 32upx 32upx 32upx 32upx;
			margin: 50% auto;
			overflow: hidden;

			.beij_txt {
				width: 488upx;
				height: 150upx;
				color: #000000;
				line-height: 49upx;
				margin: 54upx auto;
			}

			.my_yes {
				width: 552upx;
				height: 100upx;
				background: #ebbe87;
				border-radius: 0 0 32upx 32upx;
				color: #844902;
				line-height: 100upx;
			}
		}
	}

	.content_box {
		padding-left: 34upx;
		margin-top: 56upx;

		.jindu_box {
			.jindu_list {
				width: 84upx;
				height: 10upx;
				background: #f4f5f9;
				margin-left: 6upx;
			}

			.jindu_list_active {
				width: 84upx;
				height: 10upx;
				background: #ebbe87;
				margin-left: 6upx;
			}

			.jindu_list:nth-child(1) {
				margin-left: 0;
			}
		}

		.con_title {
			color: #333333;
			margin-top: 48upx;
		}

		.xuan_ze_box {
			margin-top: 70upx;

			.xuan_txt {
				color: #333333;
			}

			.xuanze_list {
				width: 718upx;
				min-height: 64upx;
				background: #f4f5f9;
				margin-top: 28upx;
				margin-left: -32upx;
				padding-left: 32upx;
				color: #999999;
				line-height: 64upx;

				.flex_box {
					margin-top: -8upx;

					.name_list {
						color: #999999;
					}

					.name_list_c {
						color: #999999;
						margin-left: 76upx;
					}
				}
			}
		}

		.list_box {
			margin-top: 82upx;
			margin-left: -20upx;
			flex-wrap: wrap;

			.fen_list {
				width: 158upx;
				height: 64upx;
				background: #f4f5f9;
				border-radius: 8upx 8upx 8upx 8upx;
				color: #666666;
				line-height: 64upx;
				margin-left: 20upx;
				margin-top: 20upx;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}

			.fen_list_active {
				width: 156upx;
				height: 64upx;
				background: #ebbe87;
				color: #844902;
				border-radius: 8upx 8upx 8upx 8upx;
			}
		}

		.scroll-Y {
			height: auto;

			.ipt_box {
				width: 686upx;
				height: 336upx;
				background: #f4f5f9;
				border-radius: 8upx 8upx 8upx 8upx;
				margin-top: 82upx;
				overflow: hidden;

				.ipt_list_box {
					width: 622upx;
					height: 80upx;
					background: #ffffff;
					border-radius: 8upx 8upx 8upx 8upx;
					margin: 24upx 0 0 32upx;

					.name {
						color: #666666;
						line-height: 80upx;
						margin-left: 24upx;
					}

					.uni-input {
						margin-top: 18upx;
						margin-left: 32upx;
					}
				}
			}
		}

		.text_area {
			width: 686upx;
			height: 60upx;
			color: #999999;
			line-height: 30upx;
			margin-top: 16upx;
		}

		.btn_tuijian {
			width: 684upx;
			height: 76upx;
			background: #f4f5f9;
			border-radius: 8upx 8upx 8upx 8upx;
			margin-top: 32upx;
			overflow: hidden;

			.con_box {
				width: 280upx;
				margin: 20upx auto;

				.jia_img {
					width: 29upx;
					height: 29upx;
				}

				.add_tuijian {
					color: #000000;
					margin-left: 20upx;
				}
			}
		}

		.btn-flii {
			height: 240rpx;
		}

		.btn {
			width: 686upx;
			height: 100upx;
			background: #ebbe87;
			border-radius: 50upx 50upx 50upx 50upx;
			position: fixed;
			bottom: 10upx;
			color: #ffffff;
			line-height: 100upx;
		}
	}
}
</style>
